package com.zust513.mapper;

import com.zust513.entity.Order;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    int getTotalDeliveryOrdersByCourierId(Integer courierId);
    int getTodayOrdersByCourierId(Integer courierId, String today);
    int getOrdersByDateRange(Integer courierId, String startDate, String endDate);
//    void acceptOrder(Integer orderId, Integer courierId);
//    void updateOrderStatus(Integer orderId, String status);
    List<Order> getDeliveryRecordsByCourierId(Integer courierId);
    List<Order> getOrdersByCourierId(Integer courierId);
    Order getOrderById(Integer orderId);

    List<Map<String, Object>> getEarningsByCourierId(Integer courierId);

    // 新增：获取配送员的所有订单
    List<Order> getAllOrdersByCourierId(@Param("courierId") Integer courierId);

    // 获取所有待分配的订单
    List<Order> getAllPendingOrders();

    // 获取当前配送员的待配送订单
    List<Order> getPendingOrdersByCourierId(@Param("courierId") Integer courierId);

    // 接取订单，更新订单的配送员 ID 和状态
    int acceptOrder(@Param("orderId") Integer orderId, @Param("courierId") Integer courierId);

    void updateOrderStatus(@Param("orderId") Integer orderId, @Param("status") String status);

    int getPendingOrderCountByCourierId(@Param("courierId") Integer courierId);

    Integer getCourierIdByOrderId(@Param("orderId") Integer orderId);

    // 确认送达，更新订单状态为已送达
    int confirmDelivery(@Param("orderId") Integer orderId, @Param("completedAt") LocalDateTime completedAt);

    //删除订单
    void deleteOrdersByIds(@Param("orderIds") List<Integer> orderIds);

    @MapKey("courierId")
    //获取已完成的订单
    List<Map<String, Object>> getCompletedOrdersByCourierId(Integer courierId);

    // 获取总订单数
    Integer getTotalOrdersCount();

    // 获取最近的订单
    @MapKey("orderId")
    List<Map<String, Object>> getRecentOrders(@Param("limit") int limit);
}